/*  File Name	: CommonStruct.h
 *  Author		: Pang Jiacai
 *	 E-mail		: 823960168@qq.com
 *  Created on	: 2012-4-5
 *  Description:
 */

#ifndef COMMONSTRUCT_H_
#define COMMONSTRUCT_H_

#include "Lock.h"

typedef  void* VOID_PTR;
class CommonList
{
public:
	CommonList(int grow_size=256);
	virtual ~CommonList();

	int put_item(VOID_PTR item);

	int get_item(VOID_PTR &item,int index);

	int cur_size(void);

	int max_size(void);

	void reset(void);

protected:
	int grow(void);

private:
	RT_MUTEX mutex_;

	int cur_size_;

	int max_size_;

	int grow_size_;

	VOID_PTR* item_ptr_;
};

///////////////////////////////////////////////

class DuplexList
{
public:
	DuplexList(int size=1024);

	virtual ~DuplexList();

	int put_obj(VOID_PTR obj);

	int get_obj(VOID_PTR &obj);

private:
	int swap_list(void);

	RT_MUTEX read_mutex_;

	RT_MUTEX write_mutex_;

	CommonList *read_list_;

	CommonList *write_list_;

	int cur_read_index_;
};

////////////////////////////////////////////////////

struct ChipsRecord
{
	ChipsRecord()
	{
		role_id =0;
		account ="";
		time = 0;
		type =0;
		amount =0;
		total_chips =0;
		room = 0;
		table = 0;
		table_index =0;
	}
	int role_id;
	std::string account;
	long time;
	int type;
	int amount;
	int total_chips;
	int room;
	int table;
	int table_index;
};
#endif /* COMMONSTRUCT_H_ */
